package org.NooLab.glue.net;

public class BoardAddress {

	public final static int __BA_DEACTIVED    = -9;
	public final static int __BA_ERROR        = -1;
	public final static int __BA_INACTIVE     = 0;
	public final static int __BA_ACTIVE       = 1;
	public final static int __BA_REGISTERING  = 2;
	public final static int __BA_TESTING      = 3;
	public final static int __BA_AVAILABLE    = 5;
	public final static int __BA_CONFIRMED    = 8;
	public final static int __BA_KNOWNMAP     = 10;
	
	
	RemoteAddress address;
	
	int state = -3 ;
	
	boolean isActive= false;
	boolean isAvailable=false;
	boolean isConfirmed=false;
	boolean isRegistering=false;
	
	long    timeOfConfirmation = 0;
	
	public BoardAddress(){
		
	}


	public boolean equals( BoardAddress ca ){
		return equals(ca,0);
	}
	public boolean equals( BoardAddress ca, int mode){
		boolean rB=false;
		
		rB = ( (address.hostname == ca.address.hostname) && 
			   (address.port == ca.address.port) ) ;
		if (mode==1){
			rB = rB && ( isActive = ca.isActive) && ( isAvailable = ca.isAvailable) ;
		}
		
		return rB;
	}
	
	
	public boolean equals( RemoteAddress ra ){
		 
		boolean rB=false;
		
		rB = ( (address.hostname == ra.hostname) && 
			   (address.port == ra.port) ) ;
		  
		return rB;
	}
	
	public RemoteAddress getAddress() {
		return address;
	}


	public void setAddress(RemoteAddress address) {
		this.address = address;
	}


	public boolean isActive() {
		return isActive;
	}


	public void setActive(boolean isActive) {
		this.isActive = isActive;
	}


	public boolean isAvailable() {
		return isAvailable;
	}


	public void setAvailable(boolean isAvailable) {
		this.isAvailable = isAvailable;
	}


	public boolean isConfirmed() {
		return isConfirmed;
	}


	public void setConfirmed(boolean isConfirmed) {
		this.isConfirmed = isConfirmed;
		
		if (state<__BA_CONFIRMED){
			state=__BA_CONFIRMED;
		}
	}


	public boolean isRegistering() {
		return isRegistering;
	}


	public void setRegistering(boolean isRegistering) {
		this.isRegistering = isRegistering;
		
		if (state<__BA_REGISTERING){
			state=__BA_REGISTERING;
		}
	}


	public int getState() {
		return state;
	}


	synchronized public void setState(int state) {
		this.state = state;
		
		if (state == __BA_REGISTERING){ isRegistering = true; };
		if (state == __BA_CONFIRMED){ isConfirmed = true; };
		if (state == __BA_AVAILABLE){ isAvailable = true; };
		
	}


	public long getTimeOfConfirmation() {
		return timeOfConfirmation;
	}


	public void setTimeOfConfirmation(long timeOfConfirmation) {
		this.timeOfConfirmation = timeOfConfirmation;
	}
	
	
	
}
